let fs = require('fs')
let path = require('path')

// 文件名
let fileNameReg = /as/

// 查找的文件夹
let defaultDir = 'C:/home/myspace/electron_test'

function FindFileInDir(dir) {
    const dirs = fs.readdirSync(dir)
    return dirs
}

function FindAllFileInDir(dir, showLog) {
    let results = []
    let files = FindFileInDir(dir)
    for (let i = 0; i < files.length; i++) {
        let file = path.join(dir, files[i]);
        let stat = fs.statSync(file)
        if (!stat.isFile()) {
            results = results.concat(FindAllFileInDir(file))
        } else {
            if (fileNameReg.test(files[i])) {
                results.push(file)
            }
        }
    }
    if (showLog) {
        console.log(`查找到文件${results.length}个`)
        for (let i = 0; i < results.length; i++) {
            console.log(results[i])
        }
    }
    return results;
}

FindAllFileInDir(defaultDir , true)